#pragma once
#include <vector>
#include <mutex>



enum class FILTERTYPE
{
	FIR = 0,
	IIR
};
enum class WINDOWTYPE
{
	RECTANGULAR = 0,
	TRIANGULAR,
	COSIN, 
	HANNING,
	HAMMING, 
	BLACKMAN,
	PAPOULIS
};

enum class PASSTYPE
{
	LOWPASS = 0,
	HIGHPASS,
	BANDPASS,
	BANDSTOP
};

class Filter
{
public:
	Filter();
	~Filter();
	void SetFilterType(FILTERTYPE type = FILTERTYPE::FIR);
	void SetWindowType(WINDOWTYPE type = WINDOWTYPE::HANNING);
	void SetPassType(PASSTYPE type = PASSTYPE::LOWPASS);
	void SetWindowSize(unsigned int size);
	void SetFilterArg(unsigned int LowFreq, unsigned int HighFreq, unsigned int SampleRate);
	std::vector<float> FilterProcess(std::vector<float> &data);
private:
	int GetFilterWindow();
	int GetFirCoefficient();
	int GetIIRCoefficient();
private:
	FILTERTYPE m_FilterType;
	WINDOWTYPE m_WindowType;
	PASSTYPE m_PassType;
	std::vector<float> m_WindowData;
	std::vector<float> m_Coff;
	std::vector<float> m_State;
	std::mutex m_mutex;
	double m_IIRa[3], m_IIRb[3];
	float m_x[2];
	float m_y[2];
	bool m_isInvalid;
	float m_FreqLow, m_FreqHigh, m_SampleRate;
	unsigned int m_WindowSize;//must be odd
};

